package org.example.code.test;

import org.example.code.entity.DailyGoods;
import org.example.code.entity.EatingGoods;
import org.example.code.entity.Goods;
import org.example.code.operation.Operation;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        List<Goods> list = new ArrayList<>();
        Goods goods1 = new EatingGoods(1,"apple",10,new BigDecimal(1),"food",false);
        Goods goods2 = new DailyGoods(2,"towel",20,new BigDecimal(2),"daily",90);
        Goods goods3 = new EatingGoods(3,"pork",30,new BigDecimal(3),"food",true);
        list.add(goods1);
        list.add(goods2);
        list.add(goods3);
        Operation op = new Operation();
        while(true) {
            System.out.println("1.添加商品");
            System.out.println("2.库存查询");
            System.out.println("3.价格调整");
            System.out.println("4.退出");
            System.out.println("请选择操作:");
            Scanner sc = new Scanner(System.in);

            String number = sc.next();
            Integer numbers;

            try {
                numbers = Integer.parseInt(number);
            } catch (NumberFormatException e) {
                System.out.println("请输入正确的序号");
                continue;
            }

            switch (numbers) {
                case 1:
                    Goods goods;
                    goods = op.addGoods(list);
                    if(goods == null){
                           break;
                    }
                    else{
                        list.add(goods);
                        System.out.println("添加成功！");
                        break;
                    }
                case 2:
                    op.goodsSelect(list);
                    break;
                case 3:
                    list = op.priceUpdate(list);
                    break;
                case 4:
                    return;
            }
        }

    }
}
